package cn.bytecollege.user.controller;

import cn.bytecollege.common.entity.User;
import cn.bytecollege.user.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserFindByIdController", value = "/user/UserFindById")
public class UserFindByIdController extends HttpServlet {
    private UserService userService = null;
    public UserFindByIdController(){
        userService = new UserService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("userId");
        Integer userId = Integer.valueOf(id);
        User user =  userService.findUserByUserId(userId);
        request.setAttribute("user",user);
        request.getRequestDispatcher("/user/userUpdate.jsp").forward(request,response);
    }
}
